//
//  NewFeatureViewController.swift
//  weibo_yaoye
//
//  Created by mac on 15/5/16.
//  Copyright (c) 2015年 mac. All rights reserved.
//

import UIKit

 //--------------step <  53 新特性  >--------nextsteplocation<<#currentfile#>>---
class NewFeatureViewController: UICollectionViewController {  //currentStep: 53

    @IBOutlet weak var layout: UICollectionViewFlowLayout!
    let imageCount = 4
    override func viewDidLoad() {
        super.viewDidLoad()
    }


    
    override func viewWillAppear(animated: Bool) { //currentStep: 53
        super.viewWillAppear(animated)
        layout.itemSize = view.bounds.size
        println("\(__FUNCTION__)\(view.frame)")
        
    }
    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {//currentStep: 53

        return imageCount
    }

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {//currentStep: 53
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("new", forIndexPath: indexPath) as! NewFeatureCell
    
        cell.ImageIndex = indexPath.item
        return cell
    }

    override func collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {//currentStep: 53
        
        let path  = collectionView.indexPathsForVisibleItems().last as! NSIndexPath
        
        if path.item == imageCount - 1{
            
            let cell = collectionView.cellForItemAtIndexPath(path) as! NewFeatureCell
            cell.startBtnshow()
        }
        
    }

}



class NewFeatureCell : UICollectionViewCell//currentStep: 53
{
    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var startButton: UIButton!
    
    var ImageIndex: Int = 0{
        didSet{
            iconView.image = UIImage(named: "new_feature_\(ImageIndex + 1)")
            startButton.hidden = true
        }
    }
    
    func startBtnshow(){//currentStep: 53
        
        startButton.hidden = false
        startButton.transform = CGAffineTransformMakeScale(0, 0)
        //--------------step 54---一种从ios7推出的一中动画----------------------------------------------------------
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: nil, animations: { () -> Void in
            self.startButton.transform = CGAffineTransformMakeScale(1.0, 1.0)
        }) { (_) -> Void in
            println("OK")
        }
    }
    @IBAction func startclick() {
        NSNotificationCenter.defaultCenter().postNotificationName(YYChooseRootVCNotification, object: "Main")
    }
    
    
}
